package cn.bugstack.springframework.beans.factory.support;

import cn.bugstack.springframework.beans.BeansException;
import cn.bugstack.springframework.beans.factory.config.BeanDefinition;

import java.util.HashMap;
import java.util.Map;

/**
 * 核心实现类
 * @author oyz
 */
public class DefaultListableBeanFactory extends AbstractAutowireCableBeanFactory implements BeanDefinitionRegistry {


    private Map<String,BeanDefinition> iocmap = new HashMap<>();



    @Override
    public BeanDefinition getBeanDefinition(String beanName) throws BeansException {
            BeanDefinition bean = iocmap.get(beanName);
            if(bean==null) {
                throw new BeansException("No bean named " + beanName + " is defined");
            }

        return bean;
    }




    @Override
    public void registerBeanDefinition(String beanName, BeanDefinition beanDefinition) {
        iocmap.put(beanName,beanDefinition);

    }

    @Override
    public boolean containsBeanDefinition(String beanName) {
        return this.iocmap.containsKey(beanName);
    }


}
